[improve][fn] Flush logs to log-topic periodically for Go Pulsar functions #22516
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Currently log messages for Go pulsar functions are only sent out to the log topic when
addLogTopicHandler
is called, which only happens when a Pulsar message is received (just before it is processed).Therefore, if a function is not processing any data, any log statements from healthchecks etc will not be sent to the log topic. Also, any log statements that occur when processing a message will only appear when another message is processed.
Modifications
After
logAppender.Start
is called, a new methodsetupLogHandlerTicker
is called to start a ticker in a goroutine.The ticker calls
flushLogsToTopicHandler
(previously namedaddLogTopicHandler
) every 100ms.The
logAppender.Stop
method has been updated to stop the ticker after one final flush of logs to the log-topic.A mutex has been added to
flushLogsToTopicHandler
to ensure that the ticker does not attempt to flush log statements to the log-topic whilst they are being flushed when a Pulsar message is received.Verifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: DavidRayner#2